export default class Pagination {
  currentPage = 1;
  totalCount = 0;
  pageSize = 20;

  constructor(pageSize) {
    if (pageSize !== undefined) {
      this.pageSize = pageSize;
    }
  }

  getTotalPage() {
    let totalPage = Math.ceil(this.totalCount / this.pageSize);
    return totalPage;
  }

  calCurrentPageByTableData(tableData, removeData) {
    let tableDataNum,removeDataNum;
    if (typeof tableData === 'number') {
      tableDataNum = tableData;
    } else {
      tableDataNum = tableData.length;
    }

    if (typeof removeData === 'number') {
      removeDataNum = removeData;
    } else {
      removeDataNum = removeData.length;
    }

    if (tableDataNum > removeDataNum) {
      return;
    }

    if (this.currentPage < this.getTotalPage()) {
      return;
    }

    let currentPage = this.currentPage - 1;
    if (currentPage < 1) {
      currentPage = 1;
    }
    this.currentPage = currentPage;
  }

  getObject() {
    return {
      limit: this.pageSize,
      page: this.currentPage
    };
  }
}
